﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Innova.Microfinanzas.BusinessEntities;
using MyCommerce.Presentation.GeneralParameters.IViews;
using Innova.FoundationFramework.DataTypes;
using MyCommerce.Business.GeneralParameters;

namespace MyCommerce.Presentation.GeneralParameters.Presenters
{
    public class CategoryAdministrationPresenter
    {
        private ICategoryAdministration pViewToPresent;

        public CategoryAdministrationPresenter(ICategoryAdministration vViewToPresent)
        {
            pViewToPresent = vViewToPresent;
            pViewToPresent.OnCreate += new EventHandler(pViewToPresent_OnCreate);
            pViewToPresent.OnDelete += new GenericEventHandler<long>(pViewToPresent_OnDelete);
            pViewToPresent.OnEdit += new GenericEventHandler<Classifier>(pViewToPresent_OnEdit);
            pViewToPresent.OnLoadView += new GenericEventHandler<long>(pViewToPresent_OnLoadView);
        }

        void pViewToPresent_OnDelete(object sender, GenericEventArgs<long> e)
        {
            try
            {
                
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        private void LoadList()
        {
            CategoryRelationDetailManager vCategoryRelationDetailManager = new CategoryRelationDetailManager();
            pViewToPresent.ColItemsList = vCategoryRelationDetailManager.GetList();
        }

        private void pViewToPresent_OnLoadView(object sender, GenericEventArgs<long> e)
        {
            LoadList();
        }

        private void pViewToPresent_OnEdit(object sender, GenericEventArgs<Classifier> e)
        {
            CategoryRelationManager vCategoryRelationManager = new CategoryRelationManager();
            bool result = pViewToPresent.InvokeEditionView(vCategoryRelationManager.GetListCategoryRelationByIdCategory(e.EventData.IdClassifier));
            if (result)
                LoadList();
        }

        private void pViewToPresent_OnCreate(object sender, EventArgs e)
        {
            bool result = pViewToPresent.InvokeEditionView(null);
            if (result)
                LoadList();
        }
    }
}
